<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
    <base href="<%=basePath%>">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
 	<%@ include file="/common/importJsCss.jsp" %>
 	<script type="text/javascript" id="preJavascript">
$(function(){
//1.一般
$.mockjax({
  url: '/restful/fortune',
  responseTime: 750,
  responseText: {
    status: 'success',
    fortune: 'Are you a turtle?'
  }
});

$.getJSON('/restful/fortune', function(response) {//成功
  if ( response.status == 'success') {
    out( 'success','/restful/fortune');
  } else {
    out('error', '/restful/fortune' );
  }
});

$.getJSON('/restful/fortune?id=1', function(response) {//失败
  if ( response.status == 'success') {
    out( 'success','/restful/fortune?id=1');
  } else {
    out('error', '/restful/fortune?id=1' );
  }
});

//2.通配符
$.mockjax({
  url: '/data/*',
  responseTime: 750,
  responseText: {
    status: 'success',
    fortune: 'Are you a turtle?'
  }
});

$.getJSON('/data/test?id=1', function(response) {//成功
  if ( response.status == 'success') {
    out( 'success','/data/test?id=1');
  } else {
    out('error', '/data/test?id=1' );
  }
});

$.mockjax({
  url: '/dataTest/test*',
  responseTime: 750,
  responseText: {
    status: 'success',
    fortune: 'Are you a turtle?'
  }
});

$.getJSON('/dataTest/test?id=1', function(response) {//成功
  if ( response.status == 'success') {
    out( 'success','/dataTest/test?id=1');
  } else {
    out('error', '/dataTest/test?id=1' );
  }
});

//3.正则表达式
$.mockjax({
  // Matches /data/quote, /data/tweet but not /data/quotes
  url: /^\/regular\/(quote|tweet)$/i,
  responseTime: 750,
  responseText: {
    status: 'success',
    fortune: 'Are you a turtle?'
  }
});

$.getJSON('/regular/quote', function(response) {//成功
  if ( response.status == 'success') {
    out( 'success','/regular/quote');
  } else {
    out('error', '/regular/quote' );
  }
});
//4.data option
$.mockjax({
  url:  '/rest',
  data: { action: "foo" },
  responseTime: 750,
  responseText: {
    status: 'success',
    fortune: 'Are you a turtle?'
  }
});

$.getJSON('/rest?action=foo', function(response) {//失败
  if ( response.status == 'success') {
    out( 'success','/rest?action=foo');
  } else {
    out('error', '/rest?action=foo' );
  }
});

$.getJSON('/rest',{ action: "foo" }, function(response) {
  if ( response.status == 'success') {
    out( 'success','/rest,{ action: "foo" }');
  } else {
    out('error', '/rest{ action: "foo" }' );
  }
});

});
	</script>
  </head>  
  <body>
  	<div class="container">
  	  	<div class="page-header">
         	<h2>url匹配</h2>
      	</div>
<pre class="prettyprint linenums"></pre>

  	</div>	
  </body>
</html>
